from django.shortcuts import render
from .models import Movie

def index(request):
    # 获取热播电影（按评分排序）
    trending_movies = Movie.objects.filter(is_trending=True).order_by('-rating')[:20]
    
    # 获取最新上映电影（按发行年份排序）
    latest_movies = Movie.objects.all().order_by('-release_year')[:20]
    
    context = {
        'trending_movies': trending_movies,
        'latest_movies': latest_movies,
    }
    
    return render(request, 'movies/index.html', context)
